package com.s08.h01.model;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.s08.h01.model.Product;

public abstract class User {

	private String name;
	private String surname;
	private Product[] cart = new Product[3];
	private BigDecimal discountedPrice;
	
	public User(String name, String surname) {
		setName(name);
		setSurname(surname);
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSurname() {
		return surname;
	}
	public void setSurname(String surname) {
		this.surname = surname;
	}
	
	public Product[] getCart() {
		return cart;
	}
	
	public void setCart(Product[] cart) {
		this.cart = cart;
	}

	public String showProducts() {
		Product[] products = getCart();
		String result = "";

		for (Product product : products) {
			if (product != null)
				result += "Product: " + product.showDesc() + product.getPrice() + "$"
				+ System.getProperty("line.separator");
		}
		return result;
	}

	public String showDiscountProducts() {
		Product[] products = getCart();
		String result = "";
		BigDecimal discount = new BigDecimal(0.1);
		
		for (Product product : products) {
			if (product != null)
				discountedPrice = product.getPrice().subtract(product.getPrice().multiply(discount));
				result += "Product: " + product.showDesc() + discountedPrice.setScale(2, RoundingMode.HALF_DOWN) + "$"
				+ System.getProperty("line.separator");
		}
		return result;
	}

	@Override
	public String toString() {
		return "User: " + name + " " + surname + " - has the following items in the cart:";
	}



	
}
